def isPrime(n):
    p = True
    if len(str(n)) != 3:
        p = False
    for i in range(2, int(n ** 0.5) + 1):
        if n % i == 0:
            p = False
            break
    return p


s = input().split()
nums = {"zero": '0',
        "one": '1',
        "two": '2',
        "three": '3',
        "four": '4',
        "five": '5',
        "six": '6',
        "seven": '7',
        "eight": '8',
        "nine": '9'}
if len(s) != 3 or not(set(s) <= set(nums.keys())):
    print("Wrong input")
    exit()

num = int(nums[s[0]] + nums[s[1]] + nums[s[2]])
r_prime = num + 1
while not isPrime(r_prime):
    r_prime += 1
l_prime = num - 1
while not isPrime(l_prime):
    l_prime -= 1
if abs(num - r_prime) < abs(num - l_prime):
    print(r_prime)
else:
    print(l_prime)